package scep.ctwing.cn.smartapp;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);

        final int SAMPLING_COUNT = 200;
        final int TOTAL_AMPLITUDE = 300;

        int[] busySpan = new int[SAMPLING_COUNT];
        int max=300;
        int min=100;
        for (int i = 0; i < SAMPLING_COUNT; i++) {
            busySpan[i] = (int) (Math.random()*(max-min)+min);
        }

        long startTime = 0;
        for (int j = 0; ; j = (j + 1) % SAMPLING_COUNT) {
            startTime = System.currentTimeMillis();
            while ((System.currentTimeMillis() - startTime) <= busySpan[j])
                ;

            try {
                Thread.sleep(TOTAL_AMPLITUDE - busySpan[j]);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

}
